package com.sofn.rest.dao;

import com.sofn.rest.model.Task;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.security.access.prepost.PreAuthorize;

public interface TaskDao extends PagingAndSortingRepository<Task, Long>, JpaSpecificationExecutor<Task> {

    @Modifying
    @Query("delete from Task task where task.uid=?1")
    void deleteByUid(Long id);

    @PreAuthorize("hasRole('ROLE_ADMIN')")
    Page<Task> findByUid(long uid, Pageable request);

    @Override
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    Page<Task> findAll(Pageable pageable);
}
